<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript">
      Ext.onReady(function(){
        //时间选择模块
        var DeadLineDateTime = new Ext.ux.form.DateTimeField({
          fieldLabel: '计划检修开工时间',
          width: 200,
          name: 'begin_time',
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "完工时间必须选择",
          emptyText: '请选择时间...'
        });

        var trainDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/train/getTrainsForCombo'}),
          reader:new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'train'
          }, [
            {name:'sn'},                            //用作后面的displayField:
            {name:'id'}                                //用作后面的valueField:
          ])
        });
        var trainIdCombo = new Ext.form.ComboBox({  //配合上面的departmentDS，完成动态生成的下拉框
          store: trainDS,
          hiddenName:'train_id',            //显示时：这里写后台传送过来的字段，一旦和valueField相等，就进行显示。不相等为空。
          displayField:'sn',              //store里面的值，用于显示在表面上的值
          valueField:'id',                  //store里面的值，和display联动
          typeAhead: true,
          allowBlank:false,
          disable:true,
          minChars:1,
          readOnly:false,
          anchor: '90%',                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
          mode: 'remote',
          fieldLabel:'列车选择',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择列车.....',
          selectOnFocus:true
        });

        var templateDS = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/template/getTemplates'}),
          reader:new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'template'
          }, [
            {name:'name'},                            //用作后面的displayField:
            {name:'id'}                                //用作后面的valueField:
          ])
        });
        var templateIdCombo = new Ext.form.ComboBox({  //配合上面的departmentDS，完成动态生成的下拉框
          store: templateDS,
          hiddenName:'template_id',                //显示时：这里写后台传送过来的字段，一旦和valueField相等，就进行显示。不相等为空。
          displayField:'name',              //store里面的值，用于显示在表面上的值
          valueField:'id',                  //store里面的值，和display联动
          typeAhead: true,
          allowBlank:false,
          disable:true,
          minChars:1,
          readOnly:false,
          anchor: '90%',                    //在容器中的时候，自动按照容器百分比进行调整，会覆盖宽度的属性
          mode: 'remote',
          fieldLabel:'模板选择',
          forceSelection: true,
          triggerAction: 'all',
          emptyText:'请选择模板.....',
          selectOnFocus:true
        });

        var newTrainRouterForm=new Ext.form.FormPanel({
          width:780,
          url:'/traintask/create?sub_type=\'一般性维护\'',
          labelAlign: 'top',
          buttonAlign:'center',
          fileUpload: true,
          autoHeight:true,
          bodyStyle: 'padding:5px',
          labelWidth:100,
          waitMsgTarget: true,
          frame: true,
          items:[{
              xtype:'textfield',
              fieldLabel:'检修任务编号',
              allowBlank:false,
              anchor: '95%',
              blankText:'项目名称不能为空！',
              name:'sn'
            },
            {
              layout:'column',
              items:[{
                  columnWidth:.33,
                  layout:'form',
                  items:[trainIdCombo]
                },{
                  columnWidth:.33,
                  layout:'form',
                  items:[templateIdCombo]
                },{
                  columnWidth:.33,
                  layout:'form',
                  items:[DeadLineDateTime]
                }
              ]
            },
            {
              xtype:'textarea',
              fieldLabel:'项目备注',
              id:'remark',
              name:'remark',
              width:755,
              height:325,
              allowBlank:true
            }
          ],
          buttons:[{
              text:'确认保存',
              handler: function(){
                Ext.get('remark').dom.value=editorInstance.GetXHTML( true );    //获取fckeditor内容赋给textarea
                // check form value
                if (newTrainRouterForm.form.isValid()) {
                  newTrainRouterForm.form.submit({
                    method: 'post',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        newTrainRouterWin.destroy();
                      }
                      else {
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                newTrainRouterWin.destroy();
              }
            }]
        });
        newTrainRouterForm.render('newTrainTaskForm');
        var oFCKeditor = new FCKeditor('remark',755,325) ;                      //注意，要放在渲染之后，否则会报错。因为Fckeditor是在页面渲染完毕后又添加的。
        oFCKeditor.BasePath = "/javascripts/fckeditor/" ;                       //根目录是Public，下面的javascripts/...
        oFCKeditor.ToolbarSet = 'Default';
        oFCKeditor.ReplaceTextarea() ;
      })
      var editorInstance;                                                       //注意，要放在FormPanel外面。
      function FCKeditor_OnComplete( instance ) {                               // FCKEditor初始化完成将调用此方法：@param {Object} editorInstance
        editorInstance=instance;
      };
    </script>
  </head>
  <body>
    <div id="newTrainTaskForm"></div>
  </body>
</html>